package com.tedu.homework;

import java.util.Scanner;

/*
* 本类用来测试分页
* */
public class TestPageSplit {
    public static void main(String[] args) {
        /*
        * 有n条结果
        * 每页显示m条
        * 问第i页显示第几条到第几条
        *
        * n % m == 0 ? "第" + i + "页是从" + ( (i - 1) * m + 1) + "条到" + m*i +"条" :
        * i < n/m+1 ? "第" + i + "页是从" + ( (i - 1) * m + 1) + "条到" + m*i +"条" :
        * "第" + i + "页是从" + ( (i - 1) * m + 1) + "条到" + n +"条"
        * */
        //创建一个Scanner对象
        Scanner scanner = new Scanner(System.in);
        //请输入总条数
        System.out.println("请输入总条数：");
        int n = scanner.nextInt();
        //请输入每页显示多少条
        System.out.println("请输入每页显示的条数：");
        int m = scanner.nextInt();
        //请输入第几页
        int pages = n%m == 0 ? n/m : n/m+1;
        System.out.println("请输入当前页数："+"(可以输入的页数范围1~"+ pages +")");
        int i = scanner.nextInt();

        //用一个result结果接收
        /*String result = n % m == 0 && i <= n / m ? "第" + i + "页是从" + ( (i - 1) * m + 1) + "条到" + m*i +"条" :
                        i < n/m+1 && n % m != 0 ? "第" + i + "页是从" + ( (i - 1) * m + 1) + "条到" + m*i +"条" :
                         i == n/m+1 ?"第" + i + "页是从" + ( (i - 1) * m + 1) + "条到" + n +"条" : "输出的页数不存在";*/
        String result = "";
       /* if( n % m == 0 && i <= n / m  ){
            result += "第" + i + "页是从" + ( (i - 1) * m + 1) + "条到" + m*i +"条";
        }else if( i < n/m+1 && n % m != 0  ){
            result +=  "第" + i + "页是从" + ( (i - 1) * m + 1) + "条到" + m*i +"条";
        }else if(i == n/m +1 ){
            result+="第" + i + "页是从" + ( (i - 1) * m + 1) + "条到" + n +"条";
        }else{
            result += "输入的页数不存在";
        }*/
        //代码的可读性
        if( (n % m == 0 && i <= n / m) || (i < n/m+1 && n % m != 0) ){
            result += "第" + i + "页是从" + ( (i - 1) * m + 1) + "条到" + m*i +"条";
        }else if(i == n/m +1 ){
            result+="第" + i + "页是从" + ( (i - 1) * m + 1) + "条到" + n +"条";
        }else{
            result += "输入的页数不存在";
        }


        //打印结果
        System.out.println( result);

    }
}
